/* ----------------------------------------------------------------------
*
* Copyright (C) 2024 XiaoFei. All rights reserved.
*
* @file:		XiaoFei_Delay.c
* @author:		XiaoFei
* @Date:     	29-April-2024
* @Revision: 	V1
* @Project: 	XiaoFei BSP Library
*
* -------------------------------------------------------------------- */

#include "stm32f4xx.h"
#include "XiaoFei_Delay.h"

/* 
* @function: 	XiaoFei_Delay_us
* @parameter:	[in] data					 The number of microseconds you want to delay.
*/
void XiaoFei_Delay_us(unsigned int xus)
{
	#ifdef Delay_UseSysTick
		SysTick->LOAD=168*xus;	
		SysTick->VAL=0x00;
		SysTick->CTRL=0x00000005;
		while(!(SysTick->CTRL&0x00010000));	
		SysTick->CTRL=0x00000004;	
	#endif
	#ifdef Delay_UseDwtTick
		CoreDebug->DEMCR|=CoreDebug_DEMCR_TRCENA_Msk;
		DWT->CYCCNT=0;
		DWT->CTRL|=DWT_CTRL_CYCCNTENA_Msk;
		while(DWT->CYCCNT<xus*168);
		DWT->CTRL&=~DWT_CTRL_CYCCNTENA_Msk;
	#endif
}

/* 
* @function: 	XiaoFei_Delay_ms
* @parameter:	[in] data					 The number of milliseconds you want to delay.
*/
void XiaoFei_Delay_ms(unsigned int xms)
{
	while(xms--)
		XiaoFei_Delay_us(1000);
}

/* 
* @function: 	XiaoFei_Delay_s
* @parameter:	[in] data					 The number of seconds you want to delay.
*/
void XiaoFei_Delay_s(unsigned int xs)
{
	while(xs--)
		XiaoFei_Delay_ms(1000);
} 


